#include "TextLayout.h"


VOID	TEXTLAYOUT::Proc(EVENTWIN Event) {
	switch (Event.Msg) {
	case WM_LBUTTONDOWN:
	case WM_LBUTTONDBLCLK: {
		INT loc = Event.Left - Left;
		INT pos = PosFromLocation(loc);
		SetAnchor(pos);
		break;
	}
	case WM_LBUTTONUP: {
		INT loc = Event.Left - Left;
		INT pos = PosFromLocation(loc);
		SetCaret(pos);
		break;
	}
	case WM_MOUSEMOVE: {
		if (Event.KeyState&MK_LBUTTON) {
			INT loc = Event.Left - Left;
			INT pos = PosFromLocation(loc);
			SetCaret(pos);
		}
		break;
	}/*
	 case WM_KEYDOWN: {
	 //switch (Event.Key) {
	 //case VK_BACK: {
	 //	if (Data().b_Focus) {
	 //		p_Table->m_TextLayout.Erase(Event);
	 //	}
	 //	break;
	 //}
	 //}//end switch
	 break;
	 }*/
	case WM_CHAR: {
		for (INT Num = 0; Num < Event.Lenth; Num++) {
			switch (Event.Key) {
			case L'\b': {
				Erase();
			}
			default: {
				Insert(Event.Key);
			}
			}//end switch
		}
		break;
	}
	default: {
		break;
	}


	}//end switch

}

VOID	TEXTLAYOUT::Paint(EVENT & Event) {
	EVENTWIN & eventwin = static_cast<EVENTWIN&>(Event);
	RECT rc;
	if (b_Focuse) {
		RECT rc = SelRect();
		OffsetRect(&rc, eventwin.Left, eventwin.Top);
		p_Render->FillRect(rc, rgb(0, 127, 0));
		rc = CaretRect();
		OffsetRect(&rc, eventwin.Left, eventwin.Top);
		p_Render->FillRect(rc, rgb(255, 0, 0));
	}

	rc = ElementRect();
	OffsetRect(&rc, eventwin.Left, eventwin.Top);
	p_Render->DrawTextW(rc, p_Text->c_str(), p_Text->size(), rgb(0, 0, 0));

}